package com.xhl.common.JdkProcy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

/**
 * @Author CazCen
 * @Date 2021/12/2 11:47
 */
public class ServiceProxy {

    /**
     * 目标类对象
     */
    private Object target;

    /**
     * InvocationHandler 接口的实现类
     */
    private InvocationHandler invocationHandler;

    public ServiceProxy(Object target, InvocationHandler invocationHandler) {
        this.target = target;
        this.invocationHandler = invocationHandler;
    }

    /**
     * 获取代理对象
     */
    public Object getProxy(){
        Object obj = Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), invocationHandler);
        return obj;
    }

}
